****************************************************************************************************************
**																											  **
** This do file is part of the replication material for the following article: 								  **
**  "Voter mobilization in the echo chamber: Broadband internet and the rise of populism in Europe" 	      **
** 		Authors: Max Schaub, Davide Morisi			    													  **
** 		Journal: European Journal of Political Research														  **
**																											  **
** This file replicates the following step of the analysis: 												  **
**																											  **
**		RECODING MERGED ITALY DATASET																		  **
**																											  **
****************************************************************************************************************

*Set working directory
cd "..."

ssc install fre
ssc install revrs

use "Replication files\italy_itanes_panel_recoded.dta", clear

**************************
*RECODING ITANES DATA

*Turnout (recalled in post-election Wave 5)
fre Q48_w5_01_W5
recode Q48_w5_01_W5 (1 3=0 "did not vote") (2=1 "went to vote") (99=.), gen(turnout)
*Vote (recalled in post-election Wave 5)
fre Q48_w5_02_03_W5
*Vote for M5S
recode Q48_w5_02_03_W5 (1/16=0 "other/dk/no reply/didnt vote") (17=1 "M5S") (18=0) (.=0) (66/99=0) if turnout!=., gen(voteM5S)
fre voteM5S
*Vote for main parties
recode Q48_w5_02_03_W5 1=1 2=2 4=2 7=3 8=4 9/11=5 17=6 3=9 5/6=9 13/16=9 18=9 .=99 66/99=99 if turnout!=., gen(vote6_all)
label de vote6_all ///
	1 "PD" ///
	2 "radical left" ///
	3 "Scelta civica Monti" ///
	4 "Pdl" ///
	5 "Lega Nord & radical right" ///
	6 "M5S" ///
	9 "other" ///
	99 "did not vote/dk/no reply"
label values vote6_all vote6_all
recode vote6_all 2=9, gen(votemulti)
label values votemulti vote6_all
fre vote6_all votemulti

*Internet main source
fre Q37_wave4_01_W4
recode Q37_wave4_01_W4 (1/6=0 "other source/dk") (7=1 "internet main source") (8/99=0), gen(internetw4_1)
label var internetw4_1 "Internet as main source of news"
*Newspaper main source of news
fre Q37_wave4_01_W4
recode Q37_wave4_01_W4 (1 2 4/7=0 "Other source/dk") (3=1 "Newspaper main source") (8/99=0), gen(newspaperw4_1)

*Gender
clonevar sex = A001 // 1=male, 2=female
label variable sex "Gender female (vs.male)"
*Age
clonevar age = A002 if A002<999
replace age = QUOTA if A002==999
gen age10 = age/10
label variable age10 "Age"
egen age_cat3 =  cut(age), at(0,18,30,60,100) icodes label
label variable age_cat3 "Age categories"
*Education
recode A004 (1 2=1 "no edu/elementary school") (3=2 "middle school") (4/11=3 "high school or above"), gen(edu3)
label var edu3 "Education level - 3 categories"
revrs edu3
rename revedu3 edu_cat3_rev
label define edu_cat3_rev 1 "Higher edu" 2 "Medium edu" 3 "Lower edu", replace
label values edu_cat3_rev edu_cat3_rev
*Employed dummy
recode Q52 (1=1 "employed") (2=0 "not employed") (99=.), gen(employed)
label var employed "Being employed"
*Type of employment
fre Q55
recode Q55 (.=0 "employed") (1=1 "retired") (2=2 "housewife") (3=3 "student") (5 6 7 9=4 "unemployed") (8 10 11 99=5 "other"), gen(unempl_type)
gen employ = .
replace employ = 1 if employed==1 & Q53==2 // employed in private sector
replace employ = 2 if employed==1 & Q53==1 // employed in public sector
replace employ = 3 if employed==0 & unempl_type==1 // retired
replace employ = 4 if employed==0 & unempl_type==2 // housewife (casalinga/o)
replace employ = 5 if employed==0 & unempl_type==3 // student
replace employ = 6 if employed==0 & unempl_type==4 // unemployed
replace employ = 7 if employed==0 & unempl_type==5 // other not working
label define employ ///
	1 "employed private sector" ///
	2 "employed public sector" ///
	3 "retired" /// 
	4 "housewife" ///
	5 "student" ///
	6 "unemployed" ///
	7 "other not working"
label values employ employ
ta employ
*Social class (based on type of employment)
gen class_cat3 = .
replace class_cat3 = 3 if Q54_W1==1 | Q54_W1==2 | Q54_W1==7 | Q54_W1==10 | Q54_W1==11
replace class_cat3 = 2 if Q54_W1==3 | Q54_W1==4 | Q54_W1==5 | Q54_W1==8 | Q54_W1==9 | Q54_W1==12 
replace class_cat3 = 1 if Q54_W1==6 | Q54_W1==8 | Q54_W1==13 | Q54_W1==15 | Q54_W1==16 | Q54_W1==17
replace class_cat3 = 3 if edu_cat3==1 & (Q55_W1==1 | Q55_W1==2 | Q55_W1==3 | Q55_W1==5 | Q55_W1==6 | Q55_W1==7 | Q55_W1==8 | Q55_W1==9 | Q55_W1==10)
replace class_cat3 = 2 if edu_cat3==2 & (Q55_W1==1 | Q55_W1==2 | Q55_W1==3 | Q55_W1==5 | Q55_W1==6 | Q55_W1==7 | Q55_W1==8 | Q55_W1==9 | Q55_W1==10)
replace class_cat3 = 1 if edu_cat3==3 & (Q55_W1==1 | Q55_W1==2 | Q55_W1==3 | Q55_W1==5 | Q55_W1==6 | Q55_W1==7 | Q55_W1==8 | Q55_W1==9 | Q55_W1==10)
label var class_cat3 "Social class"
label de class_cat3 1"Lower" 2"Middle" 3"Upper"
label val class_cat3 class_cat3
*Geographical area of residence
fre Cod_regione
recode Cod_regione 1/3=1 4/6=2 7=1 8=2 9/12=3 13/18=4 19/20=5, gen(area1)
label de area1 1 "north west" 2 "north east" 3 "centre" 4 "south" 5 "islands"
label values area1 area1
fre area1

*Left-right
fre Q34_W4
recode Q34_W4 88/99=., gen(lrscale)
gen lrscale01 = lrscale/10
label var lrscale01 "Left-right scale recoded 0-1"
label de lrscale01 0"left" 1"right"
label val lrscale01 lrscale01
recode lrscale (0/3=1 "Left") (4/6=2 "Center") (7/10=3 "Right") (.=4 "No ideology"), gen(lr4cat)
label var lrscale "Left-right scale"
label var lr4cat "Left-right scale recoded"
*Trust in parties
fre Q12_02_W5
gen trust_parties = (Q12_02_W5/10) if Q12_02_W5<88
revrs trust_parties
label variable revtrust_parties "Distrust in parties"
*Interest in politics
fre Q01_W4
gen intpol = (Q01_W4-1)/3
label variable intpol "Interest in politics"
label de intpol 0"not at all" 1"very interested"
label values intpol intpol
ta intpol
*Turnout 2008
recode Q43_W1 (88/999=0 "No") (else=1 "Yes"), gen(voted2008)
label variable voted2008 "Turnout 2008"


******************
*RECODING MUNICIPALITY LEVEL VARIABLES
*Population density
sum dens01 
gen dens011 = dens01/r(max)
label variable dens011 "Population density"
*Terrain steepness
sum slopemea_1 
gen slope1 = slopemea_1/r(max)
label variable slope1 "Terrain steepness"
*Urban vs rural
des MACRO_CLASSI
encode MACRO_CLASSI, gen(centres)
label var centres "Urban areas (centri) vs rural areas (aree interne)"
fre centres
*Unemployment rate
gen unempl_011 = unempl_01/100
label variable unempl_011 "Unemployment rate 2001"
*Ration of 65+ / 16-64 2001
sum ratio65_01 
gen ratio65_011 = ratio65_01/r(max)
label variable ratio65_011 "Ratio 65+/16-64 year-old - 2001"
*Share high education
gen edu_high_011 = edu_high_01/100
label variable edu_high_011 "Share of adults with univ degree 2001"
*Broadband 2013
*Note: original variable provides share of population WITHOUT broadband coverage
sum adsl13, d
gen bband13_01 = (-adsl13)+1 // reverse coded: from 0 (no broadband) to 1 (full coverage)
label de bband 0"no broadband" 1"full coverage"
label val bband13_01 bband
label var bband13_01 "Share covered by broadband >2Mbps (including mobile) - 2013"
fre bband13_01


******
save "Replication files\italy_itanes_panel_recoded.dta", replace


